package com.hopu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hopu.pojo.Myarea;
import com.hopu.service.AreService;
import com.hopu.util.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/are")
public class AreController {

    @Autowired
    private AreService areService;
    @RequestMapping("/findAll")
    @ResponseBody
    public ResultUtils findAll(@RequestParam(value = "pn",defaultValue = "1")Integer pn){
        System.out.println("xiaoceshi");
        PageHelper.startPage(pn,14);
        List<Myarea> all = areService.findAll();
        PageInfo page = new PageInfo(all,5);
        return new ResultUtils(200,"success",page);
    }
    @RequestMapping("/addare")
    @ResponseBody
    public ResultUtils addare(Myarea myarea){
        areService.addare(myarea);
        return new ResultUtils(200,"success",null);
    }

    @RequestMapping("/updateare")
    @ResponseBody
    public ResultUtils updateare(Myarea myarea){
        areService.updateare(myarea);
        return new ResultUtils(200,"success",null);
    }
    @RequestMapping("/findByid")
    @ResponseBody
    public ResultUtils findByid(@RequestParam("aid")Integer aid){
        Myarea byid = areService.findByid(aid);

        return new ResultUtils(200,"success",byid);

    }
    @RequestMapping("/findByname")
    @ResponseBody
    public ResultUtils findByname(@RequestParam("aname")String aname){
        Myarea byid = areService.finfByname(aname);
        System.out.println(byid);
        if(byid!=null){
            return new ResultUtils(200,"success",byid);
        };
        return new ResultUtils(20,"success",byid);
    }



}
